//
//  AppDelegate.m
//  Flower
//
//  Created by 花花 on 2016/12/2.
//  Copyright © 2016年 花花. All rights reserved.
//

#import "AppDelegate.h"
#import "HHLeadInPagesViewController.h"
#import "HHBaseTabBarViewController.h"
#import <Bugly/Bugly.h>
@interface AppDelegate ()

@end

@implementation AppDelegate

//--------------------测试是否可以提交
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    [self themeDidChange];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(themeDidChange) name:kThemeDidChangeNotification object:nil];
    
    if(![[NSUserDefaults standardUserDefaults] boolForKey:@"firstStart"]){
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstStart"];
        HHLeadInPagesViewController *leadInPageVc =[[HHLeadInPagesViewController alloc]iniitWithPagesCount:4 setupCellHandler:^(HHLeadInPagesCell *cell, NSIndexPath *indexPath) {
                        NSString *imgs =[NSString stringWithFormat:@"intro_%zd",indexPath.row];
            
            cell.imageView.image =[UIImage imageNamed:imgs];
            
            [cell.finishbtn setTitle:@"立即体验" forState:UIControlStateNormal];
            [cell.finishbtn setTitleColor:[UIColor colorWithHexString:@"fa2850"] forState:UIControlStateNormal];
            
        } finishOnClick:^(UIButton *finishbtn) {
           
            self.window.rootViewController  = [[HHBaseTabBarViewController alloc]init];
        }];
        leadInPageVc.pageControl.currentPageIndicatorTintColor =[UIColor redColor];
        leadInPageVc.pageControl.pageIndicatorTintColor =[UIColor yellowColor];
        self.window.rootViewController = leadInPageVc ;
        
    }else{
        self.window.rootViewController  = [[HHBaseTabBarViewController alloc]init];;
    }
    
    [self setupBugly];

    
    
 
    
    return YES;
}
- (void)setupBugly{


    BuglyConfig * config = [[BuglyConfig alloc] init];
    
#if DEBUG
    // SDK Debug信息开关, 默认关闭
    config.debugMode = YES;
#endif
    /**
     控制自定义日志上报，默认值为BuglyLogLevelSilent，即关闭日志记录功能。
     * 如果设置为BuglyLogLevelWarn，则在崩溃时会上报Warn、Error接口打印的日志
    
    */

    config.reportLogLevel = BuglyLogLevelWarn;
    
    
     //卡顿监控开关，默认关闭
    config.blockMonitorEnable = YES;
    
   // 卡顿监控判断间隔，单位为秒
    config.blockMonitorTimeout = 1.5;
    
    // 设置自定义渠道标识
//    config.channel = @"Bugly";
    
    //@param appId 注册Bugly分配的应用唯一标识
    //  @param development 是否开发设备
    // @param config 传入配置的 BuglyConfig

     [Bugly startWithAppId:@"69a478788a"
#if DEBUG
        developmentDevice:YES
#endif
                   config:config];
    
    // Set the customizd tag thats config in your APP registerd on the  bugly.qq.com
    // [Bugly setTag:1799];
    
    [Bugly setUserIdentifier:[NSString stringWithFormat:@"User: %@", [UIDevice currentDevice].name]];
    
    [Bugly setUserValue:[NSProcessInfo processInfo].processName forKey:@"Process"];
    
}
- (void)themeDidChange{
    
    UIImage *img =[[ThemeManager shareManager] loadImageWithImgName:@"mask_bg.jpg"];
    self.window.backgroundColor =[UIColor colorWithPatternImage:img];
}
-(void)dealloc{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
    
}


- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}


- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


@end
